package WebSum6;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class WebCountBean implements WritableComparable<WebCountBean> {

    private String province;//省

    private String year;//年份

    public WebCountBean(){
    }

    public void set(String province,String year){
        this.province = province;
        this.year = year;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }


    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    @Override
    public String toString() {
        return " " +
                "省份=" + province +
                ",年份=" + year ;
    }

    @Override
    public int compareTo(WebCountBean o) {
        int res = this.province.compareTo(o.province);
        if(res!=0){
            return res;
        }else {
            return this.year.compareTo(o.year);
        }
        //return this.province - o.getProvince() > 0 ? -1 : (this.province - o.getProvince() < 0 ? 1 : 0) ;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(province);
        dataOutput.writeUTF(year);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.province = dataInput.readUTF();
        this.year = dataInput.readUTF();
    }
}

